package com.lfs.market.controller.admin;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.annotation.SaMode;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lfs.market.model.R;
import com.lfs.market.model.dto.SystemProductTypePageDto;
import com.lfs.market.model.entity.ProductType;
import com.lfs.market.service.ProductTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/product/type")
@SaCheckLogin
@SaCheckRole(value = {"system", "admin"}, mode = SaMode.OR)
public class ProductTypeAdminController {
    @Autowired
    private ProductTypeService productTypeService;

    /**
     * 查询商品分类列表
     *
     * @param dto
     * @return
     */
    @GetMapping("/page")
    public R<Page> getTypePageList(SystemProductTypePageDto dto) {
        Page page = productTypeService.getTypePageList(dto);
        return R.ok(page);
    }

    /**
     * 添加商品分类
     *
     * @param type 分类
     * @return
     */
    @PostMapping
    public R createType(@RequestBody ProductType type) {
        productTypeService.createType(type);
        return R.ok();
    }

    /**
     * 编辑商品分类
     *
     * @param type
     * @return
     */
    @PutMapping
    public R editType(@RequestBody ProductType type) {
        productTypeService.editType(type);
        return R.ok();
    }

    /**
     * 根据分类id删除商品分类
     *
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public R delType(@PathVariable("id") String id) {
        productTypeService.removeById(id);
        return R.ok();
    }
}
